/**
 * @date 2:39:01 PM
 * EducationAdmin.java
 * Administrator
 * TODO
 */
package com.qs.education.bean.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.qs.education.bean.dao.IEducationAdminDao;
import com.qs.education.bean.entity.EducationAdmin;
import com.qs.education.bean.entity.EducationTeacher;

/**
 * @class EducationAdmin
 * @author Brooks
 * @description 
 * @date Oct 17, 2018
 */
@Repository
public class EducationAdminDaoImpl extends BaseDaoImpl<EducationAdmin> implements IEducationAdminDao{
	
	/**
	 * @description 根据用户名和密码得到当前管理员
	 * @user Brooks
	 * @date Oct 17, 2018
	 * @return EducationAdmin
	 */
	public EducationAdmin getEducationAdmin(String name,String password) {
		String jql="Select ea from EducationAdmin ea where ea.name=:name and ea.password=:password";
		Query query = this.em.createQuery(jql);
		query.setParameter("name", name);
		query.setParameter("password", password);
		@SuppressWarnings("unchecked")
		List<EducationAdmin> list = query.getResultList();
		if(list != null && list.size()>0){
			return list.get(0);
		} else {
			return null;
		}
	}


	@Override
	public EducationAdmin findAdminByName(String name) {
		String jql = "from EducationAdmin ea where ea.name = :name";
		Map<String, Object> params = new HashMap<>();
		params.put("name", name);
		List<EducationAdmin> result = query(jql, EducationAdmin.class, params);
		if(null != result && !result.isEmpty()){
			return result.get(0);
		}
		return null;
	}

}
